﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XLang
{
    public static class TypeExtension
    {
        public static bool IsInherit(this Type type, Type baseType)
        {
            var tmp = type;
            while (tmp != null)
            {
                if (tmp.BaseType == baseType) return true;
                tmp = tmp.BaseType;
            }
            return false;
        }

        public static bool IsToken(this Type type) {
            return TypeExtension.IsInherit(type, typeof(Token));
        }

        public static bool IsAST(this Type type) {
            var tokenType = typeof(Token);
            var astType = typeof(AST);

            var tmp = type;
            while (tmp != null)
            {
                if (tmp.BaseType == tokenType) return false;
                if (tmp.BaseType == astType) return true;
                tmp = tmp.BaseType;
            }
            return false;
        }
    }
}
